package com.example.huitong.db;

import com.example.huitong.db.DBContract.TableUser;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;



public class DBHelper extends SQLiteOpenHelper {
	
	private static final String DATABASE_NAME = "huitong_app.db";
	
    private static final int DATABASE_VERSION = 1;
	private static final String TAG = "DBHelper";
	
	interface Tables {
		String TABLE_USER = "t_user";
	}

	public DBHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		 db.execSQL("CREATE TABLE " + Tables.TABLE_USER + " ("
                 + TableUser.NAME + " TEXT PRIMARY KEY,"
                 + TableUser.PASSWORD + " TEXT,"
                 + TableUser.PHONE + " TEXT"
                 + ");");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		 // Logs that the database is being upgraded
        Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
                + newVersion + ", which will destroy all old data");

        // Kills the table and existing data
        db.execSQL("DROP TABLE IF EXISTS notes");

        // Recreates the database with a new version
        onCreate(db);
	}

}
